<?php

/**
 * Description of G_Configs
 * @author 耿鸿飞<eoe2005@qq.com>
 */
class G_Config {

    protected static $_config;

    public static function init($conf) {
        if (self::$_config) {
            return self::$_config;
        } else {
            $index = strpos($conf, '://');
            if ($index !== false) {
                $drive = strtolower(trim(substr($conf, 0, $index)));
                $filepath = substr($conf, $index + 3);
                if ($drive == 'ini') {
                    include G_ROOT . 'Config' . DS . 'G_IniConfig.cls.php';
                    self::$_config = new G_IniConfig($filepath);
                } elseif ($drive == 'xml') {
                    include G_ROOT . 'Config' . DS . 'G_XmlConfig.cls.php';
                    self::$_config = new G_XmlConfig($filepath);
                } elseif ($drive == 'json') {
                    include G_ROOT . 'Config' . DS . 'G_JsonConfig.cls.php';
                    self::$_config = new G_IniConfig($filepath);
                } else {
                    trigger_error("配置文件配置错误");
                    die();
                }
            } else {
                trigger_error("配置文件配置错误");
                die();
            }
        }
    }

    public static function getItem($key) {
        if (self::$_config) {
            return self::$_config->getItem($key);
        }
        return NULL;
    }

}

abstract class GC_Config {

    public abstract function getItem($key);
}
